﻿/*
* 创建者：LIYINFAI
* 创建时间：2023/10/24 9:35:26
* 描述：
* --------------------------------------
* 修改说明：
* --------------------------------------
*/
using Newtonsoft.Json;
using System;
using System.ComponentModel;
using System.IO;

namespace CommonLibrary
{
    /// <summary>
    /// APP相关的PLC配置内容
    /// </summary>

    public class AppPLCSetting
    {
        /// <summary>
        /// 配置文件路径
        /// </summary>
        private static string CONFIG_FILE_PATH = Path.Combine(CommonHelper.COMMON_CONFIG_DIR, "AppPLCConfig.json");
        /// <summary>
        /// 来料数量PLC地址
        /// </summary>
        [Description("来料数量PLC地址")]
        [JsonProperty(PropertyName = "InboundNumAddress")]
        public string InboundNumAddress { get; set; } = "";
        /// <summary>
        /// 扫码NG数量PLC地址
        /// </summary>
        [Description("扫码NG数量PLC地址")]
        [JsonProperty(PropertyName = "ScanNGNumAddress")]
        public string ScanNGNumAddress { get; set; } = "";
        /// <summary>
        /// 出料数量PLC地址
        /// </summary>
        [Description("出料数量PLC地址")]
        [JsonProperty(PropertyName = "OutboundNumAddress")]
        public string OutboundNumAddress { get; set; } = "";
        /// <summary>
        /// 氦检数量PLC地址
        /// </summary>
        [Description("氦检数量PLC地址")]
        [JsonProperty(PropertyName = "HeliumNumAddress")]
        public string HeliumNumAddress { get; set; } = "";
        /// <summary>
        /// 氦检NG数量PLC地址
        /// </summary>
        [Description("氦检NG数量PLC地址")]
        [JsonProperty(PropertyName = "HeliumNGNumAddress")]
        public string HeliumNGNumAddress { get; set; } = "";
        /// <summary>
        /// 耐压测试数量PLC地址
        /// </summary>
        [Description("耐压测试数量PLC地址")]
        [JsonProperty(PropertyName = "PressTestNumAddress")]
        public string PressTestNumAddress { get; set; } = "";
        /// <summary>
        /// 耐压测试NG数量PLC地址
        /// </summary>
        [Description("耐压测试NG数量PLC地址")]
        [JsonProperty(PropertyName = "PressTestNGNumAddress")]
        public string PressTestNGNumAddress { get; set; } = "";
        /// <summary>
        /// 绝缘测试数量PLC地址
        /// </summary>
        [Description("绝缘测试数量PLC地址")]
        [JsonProperty(PropertyName = "InsulationTestNumAddress")]
        public string InsulationTestNumAddress { get; set; } = "";
        /// <summary>
        /// 绝缘测试NG数量PLC地址
        /// </summary>
        [Description("绝缘测试NG数量PLC地址")]
        [JsonProperty(PropertyName = "InsulationTestNGNumAddress")]
        public string InsulationTestNGNumAddress { get; set; } = "";
        /// <summary>
        /// PC心跳监控地址
        /// </summary>
        [Description("PC心跳监控地址")]
        [JsonProperty(PropertyName = "PCHeartbeat")]
        public string PCHeartbeat { get; set; }
        /// <summary>
        /// 是否触发停机原因上传地址
        /// </summary>
        [Description("是否触发停机原因上传地址")]
        [JsonProperty(PropertyName = "StopReasonRequest")]
        public string StopReasonRequest { get; set; }
        /// <summary>
        /// 设备状态监控地址
        /// </summary>
        [Description("设备状态监控地址")]
        [JsonProperty(PropertyName = "EQMStatus")]
        public string EQMStatus { get; set; }
        /// <summary>
        /// 上位机注销用户地址
        /// </summary>
        [Description("上位机注销用户地址")]
        [JsonProperty(PropertyName = "IsLogout")]
        public string IsLogout { get; set; }
        private static object LOCK_OBJ = new object();
        private static AppPLCSetting instance = null;
        /// <summary>
        /// 单例对象
        /// </summary>
        /// <param name="reload"></param>
        /// <returns></returns>
        public static AppPLCSetting Instance(bool reload = false)
        {
            if (reload || instance == null)
            {
                try
                {
                    instance = CommonHelper.GetJsonFromFile(CONFIG_FILE_PATH, new AppPLCSetting());
                }
                catch (Exception ex)
                {
                    instance = new AppPLCSetting();
                    LogHelper.Error(ex);
                }
            }
            return instance;
        }
        /// <summary>
        /// 保存
        /// </summary>
        public void Save()
        {
            lock (LOCK_OBJ)
            {
                CommonHelper.SaveToJsonFile(instance, CONFIG_FILE_PATH);
            }
        }
        /// <summary>
        /// 描述信息
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return CommonHelper.GetObjectString(this);
        }
    }
}
